package com.xiangyueEducation.uploaderCloud.service.entity.impl;

import com.xiangyueEducation.uploaderCloud.mapper.DiaryMapper;
import com.xiangyueEducation.uploaderCloud.pojo.entity.Diary;
import com.xiangyueEducation.uploaderCloud.service.entity.DiaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DiaryServiceImpl implements DiaryService {

    private final DiaryMapper diaryMapper;

    @Autowired
    public DiaryServiceImpl(DiaryMapper diaryMapper) {
        this.diaryMapper = diaryMapper;
    }

    @Override
    public int createDiary(Diary diary) {
        return diaryMapper.insertDiary(diary);
    }

    @Override
    public List<Diary> getDiariesByUserId(Long userId) {
        return diaryMapper.selectByUserId(userId);
    }

    @Override
    public List<Diary> getAllActiveDiaries() {
        return diaryMapper.selectAllActiveDiaries();
    }

    @Override
    public Diary getDiaryById(Long diaryId) {
        // 直接获取单条日记
        return diaryMapper.selectDiaryById(diaryId);
    }


    @Override
    public List<Diary> getDiariesByDateRange(String startTime, String endTime) {
        return diaryMapper.selectDiariesByDateRange(startTime, endTime);
    }

    @Override
    public List<Diary> getDiariesByKeyword(String keyword) {
        return diaryMapper.selectDiariesByKeyword(keyword);
    }
}
